/**
 * Created by cheny on 2016/1/26.
 */

var urllib = require("urllib");

exports.getTicket = function(access_token, callback){
    var url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + access_token + "&type=jsapi";
    var options = {
        method: "GET",
        dataType: "json"
    };
    urllib.request(url, options, function(err, body, resp){
        if(err){
            callback(err);
            return;
        }
        if(resp.statusCode !== 200){
            callback("Http响应码必须是200");
            return;
        }
        if(body.errcode){
            callback(body);
            return;
        }
        console.log('body.ticket:'+body.ticket);
        callback(null, body.ticket);
    });
};
